package org.zappee.peterk.custom.tests.controller
{
	import org.zappee.peterk.custom.controller.BugFormController;
	import org.zappee.peterk.custom.controller.interfaces.IBugFormController;
	import org.zappee.peterk.custom.model.BugModel;
	import org.zappee.peterk.custom.model.interfaces.IBugModel;
	
	import flexunit.framework.TestCase;
	
	import mx.collections.ArrayCollection;
	
	public class BugFormControllerTests extends TestCase
	{
		protected var bugModel: IBugModel;
		
		protected var controller: IBugFormController;
		
		public function BugFormControllerTests()
		{
			// setup model
			this.bugModel = new BugModel();	
			this.bugModel.bugs = new ArrayCollection();
			
			this.controller = new BugFormController();
			this.controller.bugModel = this.bugModel;
			
		}
        
        public function testSave(): void
        {
        	var bugCount: int = this.bugModel.bugs.length;
        	
			this.controller.updateAssignedTo("peter@moov2.com");
			this.controller.updateDescription("This is a description");
			this.controller.updatePriority("High");
			this.controller.updateTitle("Bug");
			
			this.controller.save()
			
        	assertEquals("Expecting amount of bugs to increase by one.", bugCount + 1, this.bugModel.bugs.length);
        }
        
        public function testValidate(): void
        {
        	assertFalse("Expecting validation to return false.", this.controller.validate());
        	
        	this.controller.updateAssignedTo("peter@moov2.com");
        	
        	assertFalse("Expecting validation to fail.", this.controller.validate());
        	
        	this.controller.updateDescription("This is the description");
        	
        	assertFalse("Expecting validation to fail.", this.controller.validate());
        	
        	this.controller.updatePriority("High");
        	
        	assertFalse("Expecting validation to fail.", this.controller.validate());
        	
        	this.controller.updateTitle("Bug Title");
        	
        	assertTrue("Expecting validation to pass.", this.controller.validate());
        }
	}
}